package handler;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import bean.Entity;
import configure.service.EntityService;

@Controller
@RequestMapping(path = "/mapping/")
public class RequestMappingHandler {
    @Autowired
    private EntityService service;

    public void setService(@Qualifier(value = "service") EntityService service) {
        this.service = service;
    }

    @RequestMapping(value = "get-json")
    public ModelAndView handle(Model model) {
        Set<Entity> entities = service.query();
        model.addAttribute(entities);
        ModelAndView modelAndView = new ModelAndView("index", model.asMap());
        return modelAndView;
    }
}
